<?php

namespace App\Admin\Forms;


use App\Models\ChatContentModel;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Arr;

class WangEditor extends Form
{
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $array = Arr::only($input, ['name', 'content', 'created_at', 'sender', 'receiver']);
        $chatContentModel = new ChatContentModel;
        foreach ($array as $key => $value) {
            $chatContentModel->$key = $value;
        }
        $isSuccess = $chatContentModel->save();
        if ($isSuccess) {
            return $this
                ->response()
                ->success('发送成功')
                ->refresh();
        }

        return $this->response()->error('发送失败');
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->hidden('name');
        $this->editor('content', '');
        $this->hidden('created_at');
        $this->hidden('sender');
        $this->hidden('receiver');
        // 去掉`重置`按钮
        $this->disableResetButton();
        $this->width(20, 0);
    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        return [
            'name' => '客服',
            'created_at' => date('Y-m-d H:i:s'),
            'sender' => 1,
            'receiver' => 2,
        ];
    }
}
